﻿using System;
using System.Drawing;
using System.ComponentModel;
using SedionFormDesigner.CusControls.Infrastructure;

namespace SedionFormDesigner.CusControls
{
    public class BD_Label : System.Windows.Forms.Label
    {
        int i = 0;
        public BD_Label()
            : base()
        {

        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            if (i == 0)
            {
                base.Height = 21;
            }
            i++;
        }

        #region 属性:外观

        private float _fontsize = 9;//字体大小
        private bool _fontbold = false;//是否粗体
        private bool _fontitalic = false;//是否斜体
        private TextAlign _textAlign = TextAlign.left;
        private String _name = String.Empty;

        [Category("设计")]
        [ReadOnly(true)]
        public String NewName
        {
            get
            {
                _name = _name == String.Empty ? base.Name : _name;
                return _name;
            }
            set
            {
                _name = value;
                base.Name = _name;
            }
        }

        [Category("外观")]
        public float FontSize
        {
            set { _fontsize = value; FontChange(); }
            get { return _fontsize; }
        }

        [Category("外观")]
        public bool FontBold
        {
            set { _fontbold = value; FontChange(); }
            get { return _fontbold; }
        }

        [Category("外观")]
        public bool FontItalic
        {
            set { _fontitalic = value; FontChange(); }
            get { return _fontitalic; }
        }

        [Category("外观")]
        public new TextAlign TextAlign
        {
            set
            {
                _textAlign = value;
                switch (_textAlign)
                {
                    case TextAlign.left:
                        base.TextAlign = ContentAlignment.MiddleLeft;
                        break;
                    case TextAlign.center:
                        base.TextAlign = ContentAlignment.MiddleCenter;
                        break;
                    case TextAlign.right:
                        base.TextAlign = ContentAlignment.MiddleRight;
                        break;
                    default:
                        break;
                }
            }
            get { return _textAlign; }
        }

        void FontChange()
        {
            if (_fontbold && _fontitalic)
                base.Font = new Font(base.Font.FontFamily.Name, _fontsize, FontStyle.Bold | FontStyle.Italic);
            else if (_fontbold && !_fontitalic)
                base.Font = new Font(base.Font.FontFamily.Name, _fontsize, FontStyle.Bold);
            else if (!_fontbold && _fontitalic)
                base.Font = new Font(base.Font.FontFamily.Name, _fontsize, FontStyle.Italic);
            else
                base.Font = new Font(base.Font.FontFamily.Name, _fontsize);
        }

        #endregion
    }
}
